package com.wanmao.test.service;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.wanmao.test.bean.GongGongBeanResultValueDATAS;
import com.wanmao.test.dbhelper.DBOpenHelper;


public class DBService {
    private DBOpenHelper dBOpenHelper;

    public DBService(Context context) {
        this.dBOpenHelper = new DBOpenHelper(context);
    }
    private ContentValues settingValue(GongGongBeanResultValueDATAS prDetail) {
        ContentValues values = new ContentValues();
        values.put("OBJ_ID", prDetail.getOBJ_ID());
        values.put("DM", prDetail.getDM());
        values.put("DMMC", prDetail.getDMMC());
        values.put("DMLB", prDetail.getDMLB());
        values.put("DMLBMC", prDetail.getDMLBMC());
        values.put("BZ", prDetail.getBZ());
        values.put("SFXS", prDetail.getSFXS());

        return values;
    }

    public void save(GongGongBeanResultValueDATAS prDetail) {
        SQLiteDatabase db = dBOpenHelper.getWritableDatabase();
        db.insert("T_ZH_JSJD_GGDM", null, settingValue(prDetail));
    }

    public String getDMMCName(String DM,String DMLB){
        String sql = "select * from T_ZH_JSJD_GGDM where DM=? and DMLB=?";
        String DMMC="";
        SQLiteDatabase db = dBOpenHelper.getWritableDatabase();
        Cursor cursor = db.rawQuery(sql,new String[]{DM,DMLB});

        while (cursor.moveToNext()){
            DMMC=cursor.getString(cursor.getColumnIndex("DMMC"));
            cursor.close();
            db.close();
            return DMMC;
        }
        cursor.close();
        db.close();
        return null;
    }

}
